home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
clang
/
tcplusx.zip
/
MOUSE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-28
|
8KB
|
330 lines
//
// mouse.cpp - implementation for class Mouse
// Author - Robin W. McKean
// Last Update - February 23,1991
// Copyright (C) 1991 All rights reserved
//
// This file remains the property of the author, Robin W. McKean. You are
// free to use and change it as you see fit. This module, nor its object
// code, may not however be included in any packaged software without the
// written consent of the author.
//
// Contents ----------------------------------------------------------------
//
// Mouse::Mouse
// Mouse::isA
// Mouse::nameOf
// Mouse::processA
// Mouse::pollDevice
//
// Description
//
// Defines the class Mouse. The purpose of this class is to allow
// the mouse to be used as input also, in a manner that is tranparent
// to the programmer. This is utlimate integrated input devices!
//
// End ---------------------------------------------------------------------
// Interface dependencies --------------------------------------------------
#ifndef _IOSTREAM_H
#include <iostream.h>
#endif
#ifndef _USETYPES_H
#include <usetypes.h>
#endif
#ifndef _GEN_H
#include <gen.h>
#endif
#ifndef _EVENT_H
#include <event.h>
#endif
#ifndef _MOUSE_H
#include <mouse.h>
#endif
// End Interface dependencies ----------------------------------------------
// Implementation dependencies ---------------------------------------------
#ifndef _DOS_H
#define _DOS_H
#include <dos.h>
#endif
#ifndef _CONIO_H
#define _CONIO_H
#include <conio.h>
#endif
// End Implementation dependencies -----------------------------------------
// Member Function //
Mouse::Mouse( int initStatus ) : Device( initStatus )
// Summary ------------------------------------------------------------------
//
// Sets the initial status of the mouse. It is the responsibility of
// of the constructor to determine if a mouse driver is present on the
// system currently in use.
//
// End ---------------------------------------------------------------------
{
REGS regs;
// Set the device type, and mouse button press information to defualt
type = D_MOUSE;
mouseButtonPressed = 0;
// Use BIOS ( DOS ) to call mouse driver
regs.x.ax = 0;
int86( 0x33, ®s, ®s );
// If device returned 0xffff, then device has been reset
if( regs.x.ax == -1 )
{
status = D_ON;
cellWidth = 8; // Reset these to change mouse bounds
cellHeight = 8;
lines = 24;
columns = 79;
}
else
status = D_INACTIVE; // No device available for us!
}
// End Mouse::Mouse //
// Member Function //
#pragma argsused
Mouse::Mouse( Device& theDevice )
// Description -------------------------------------------------------------
//
// Copies one Mouse into another
//
// Parameters
//
// Device&
//
// The Mouse to be copied
//
// End ---------------------------------------------------------------------
{
mouseButtonPressed = ( ( Mouse& ) theDevice ).mouseButtonPressed;
status = ( ( Mouse& ) theDevice ).status;
}
// End Mouse::Mouse //
// Member Function
Mouse::~Mouse( )
// Description --------------------------------------------------------------
//
// This destructor turns the mouse cursor off. Evidently there is some
// bug about the program supposedly automatically turning the mouse off.
// It never hurts to be sure.
//
// End ----------------------------------------------------------------------
{
REGS regs;
// Turn the mouse cursor off
regs.x.ax = 2;
int86( 0x33, ®s, ®s );
}
// Mouse::~Mouse //
// Member Function //
classType Mouse::isA( ) const
// Description -------------------------------------------------------------
//
// Returns a value representation of a class
//
// End ---------------------------------------------------------------------
{
return mouseClass;
}
// End Mouse::isA( ) //
// Member Function //
char *Mouse::nameOf( ) const
// Description -------------------------------------------------------------
//
// Returns a character representation of a class
//
// End ---------------------------------------------------------------------
{
return "Mouse";
}
// End Mouse::nameOf //
// Member Function //
void Mouse::pollDevice( )
// Description -------------------------------------------------------------
//
// This reads the mouse for input. If a mouse button is pressed, it
// it checks to see if the mouse button was pressed last time we came
// through. If it was, we have a continued selection. Otherwise we
// have a first time selection. If a button is not pressed, nothing
// happens.
//
// End ---------------------------------------------------------------------
{
REGS regs;
Event event;
event.type = 0;
// if mouse not properly installed, return
if( status == D_INACTIVE || status == D_OFF ) return;
// Get the current mouse status
regs.x.ax = 3;
regs.x.bx = 0;
int86( 0x33, ®s, ®s );
event.point.row = regs.x.dx / cellHeight;
event.point.column = regs.x.cx / cellWidth;
// if the last mouse operation was not a button press, get one now
if( !mouseButtonPressed )
{
mouseButtonPressed = regs.x.bx;
if( mouseButtonPressed )
{
event.type = E_MOUSE;
switch( mouseButtonPressed )
{
case 1:
event.typeCode = M_LEFT_SELECT; // Left button press
break;
case 2:
event.typeCode = M_RIGHT_SELECT; // Right button press
break;
case 4:
event.typeCode = M_MIDDLE_SELECT; // Middle button press
break;
}
}
}
else
{
// Last event from here was a button press
event.type = E_MOUSE;
// Check to see who has been released
if( regs.x.bx == mouseButtonPressed )
{
// Button still is being pressed, so send continue
switch( regs.x.bx )
{
case 1:
event.typeCode = M_LCONTINUE_SELECT;
break;
case 2:
event.typeCode = M_RCONTINUE_SELECT;
break;
case 4:
event.typeCode = M_MCONTINUE_SELECT;
break;
}
}
else
{
// Button has to be released, send proper release button
event.type = E_MOUSE;
switch( mouseButtonPressed )
{
case 4:
event.typeCode = M_MIDDLE_RELEASE;
break;
case 2:
event.typeCode = M_RIGHT_RELEASE;
break;
default:
event.typeCode = M_LEFT_RELEASE;
}
mouseButtonPressed = 0;
}
}
// If we found a event, stuff the queue with it
if( event.type && theEventManager ) theEventManager->putEvent( event, FALSE );
}
int Mouse::processA( Event& theEvent )
{
REGS regs;
// If we are not active, then don't process event
if( status == D_INACTIVE || status == D_OFF ) return( 0 );
switch( theEvent.typeCode )
{
case D_ON:
case D_SHOW:
regs.x.ax = 1; // Turn mouse on
int86( 0x33, ®s, ®s );
break;
case D_OFF: // Turn mouse off
case D_HIDE:
regs.x.ax = 2;
int86( 0x33, ®s, ®s );
break;
case D_POSITION: // position mouse
regs.x.ax = 4;
regs.x.cx = ( unsigned int )theEvent.point.column * cellWidth;
regs.x.dx = ( unsigned int )theEvent.point.row * cellHeight;
int86( 0x33, ®s, ®s );
break;
case D_INIT:
// Set the mouses horizontal bounds
regs.x.ax = 7;
regs.x.cx = 0;
regs.x.dx = ( unsigned int )columns * cellWidth;
int86( 0x33, ®s, ®s );
// Set the mousees vertical bounds
regs.x.ax = 8;
regs.x.cx = 0;
regs.x.dx = ( unsigned int )lines * cellHeight;
int86( 0x33, ®s, ®s );
// Set the cursor state
regs.x.ax = 10;
regs.x.bx = 0;
regs.x.cx = 0xffff;
regs.x.dx = 0x7700;
int86(0x33,®s,®s);
// Now turn the mouse cursor on
regs.x.ax = 1;
int86( 0x33, ®s, ®s );
break;
}
return( 0 );
}